#include <mpi.h>
#include <stdio.h>

#include "utils.h"


int add_matrix(struct matrix_t* a, struct matrix_t* b);

int main(int argc, char** argv)
{
	struct MPI_Info info;
	struct matrix_t* mat;
	struct matrix_t* smat;
	struct matrix_t* ans_mat;
	long i, j;
	long ans;

	MPI_Init(&argc, &argv);

	get_mpi_info(&info);
	read_matrix("A.txt", &mat);
	read_matrix("B.txt", &smat);
	alloc_matrix(&ans_mat, mat->m, smat->n);

	for (i = 0; i < ans_mat->m; ++i) {
		for (j = 0; j < ans_mat->n; ++j) {
			mat_prod(mat, smat, i, j, &ans);
			set_elem(ans_mat, i, j, ans);
		}
	}

	for (i = 0; i < ans_mat->m; ++i) {
		for (j = 0; j < ans_mat->n; ++j) {
			printf("%ld\t", get_elem(ans_mat, i, j));
		}
		printf("\n");
	}

	MPI_Barrier(MPI_COMM_WORLD);
	MPI_Finalize();

	return 0;
}
